package com.sistemavendas.modelo;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;


public class HibernateUtil 
{
	private static SessionFactory session = buildSessionFactory();
	private static ServiceRegistry serviceRegistry;
	
	private static SessionFactory buildSessionFactory()
	{
		try
		{
			Configuration configuration = new Configuration().configure();
            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            session = configuration.buildSessionFactory(serviceRegistry);
	        return session;
		}
		catch(Throwable exe)
		{
			exe.printStackTrace();
			System.out.println("Deu erro");
			throw new ExceptionInInitializerError();
		}
	}
	
	public static SessionFactory getSession()
	{
		return session;
	}

}
